/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.dailyinfo.smscbclient;

import org.apache.log4j.Level;
import org.apache.log4j.WriterAppender;
import org.apache.log4j.spi.LoggingEvent;
import org.openide.windows.IOProvider;
import org.openide.windows.InputOutput;

/**
 *
 * @author GiangLT
 */
public class OutputWindowAppender extends WriterAppender {

    @Override
    public void append(LoggingEvent event) {
        final String message = this.layout.format(event);
        InputOutput io = IOProvider.getDefault().getIO("Log", false);

        if (event.getLevel().equals(Level.ERROR) || event.getLevel().equals(Level.WARN)
                || event.getLevel().equals(Level.FATAL)) {
            io.getErr().print(message);
        } else {
            io.getOut().print(message);
        }
    }
}
